package com.alison.SmartCli.BuiltInFunction;

import com.alison.SmartCli.MethodData;

public class UsageFunction implements BuiltIn{

    @Override
    public void execute(String[] args) {
        if(args.length == 0){
            System.out.println(description());
        }
        final String methodName = args[0];
        String usage = "method not existed";
        if (BuiltInManager.isBuiltInFunction(methodName)){
            usage = BuiltInManager.getFunction(methodName).description();
        }else if (MethodData.containUserMethod(methodName)){
            usage = MethodData.getUsage(methodName);
        }
        System.out.println(methodName+" : "+usage);
    }

    @Override
    public String description() {
        return "usage [functionName]: show the function's usage";
    }


}
